package userConsole.servlet;

import org.json.JSONException;
import org.json.JSONObject;
import userConsole.service.PageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Godv
 * @version 1.0
 */
@WebServlet("/page")
public class PageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String showCount = req.getParameter("showCount");
        String page = req.getParameter("page");
        try {
            if(showCount == null || "".equals(showCount))
                showCount = "5";                              // 默认值为每页显示5条
            if(page == null || "".equals(page))
                page = "1";                                   // 默认值为页码第一页
            StaticPrint.print(resp, new PageService().page(showCount, page));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
